package com.szqhyxj.youxiangju.biz.partnerHome.shop.order;

import com.szqhyxj.youxiangju.biz.merchantHome.bean.OrderDeetails;
import com.szqhyxj.youxiangju.biz.merchantHome.shop.order.OrderModel;
import com.szqhyxj.youxiangju.sys.AbBasePresenter;
import com.szqhyxj.youxiangju.sys.BaseResult;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

class SubordinateOrderDetailsPresenter extends AbBasePresenter implements SubordinateOrderDetailsContract.Presenter {

    private final SubordinateOrderDetailsContract.View view;
    private SubordinatePartnerOrderModel.PartnerOrderOutEntity entity;
    public SubordinateOrderDetailsPresenter(SubordinateOrderDetailsContract.View view){
        this.view = view;
        entity = new SubordinatePartnerOrderModel.PartnerOrderOutEntity();
    }

    @Override
    public void initOrderDetail(String orderId){
        entity.setOrderNo(orderId);

        addDisposables(OrderModel.getOrderDetail(orderId)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<BaseResult<OrderDeetails>>(){
                    @Override
                    public void accept(BaseResult<OrderDeetails> orderDeetailsBaseResult) throws Exception{
                        view.dismissLoading();
                        if(orderDeetailsBaseResult.businessLogicSuccess()){
                            view.showOrderDetails(orderDeetailsBaseResult.getData());
                        }else {
                            view.showToast(orderDeetailsBaseResult.getMessage());
                        }
                    }
                }, new Consumer<Throwable>(){
                    @Override
                    public void accept(Throwable throwable) throws Exception{
                        view.showToast(throwable.getMessage());
                        view.dismissLoading();
                    }
                }));
    }


    @Override
    public void nowConfirm(){
        view.navConfirmOrder();
    }

    @Override
    public void addDisposables(Disposable disposable){
        super.addDisposables(disposable);
        view.showLoading();
    }
}